package org.hadoop.hive.example;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @Author: chengjj
 * @Date: 2020-07-24
 */
public class JdbcTest {

    public static void main(String[] args) throws Exception {
//加载驱动
        Class.forName("org.apache.hive.jdbc.HiveDriver");
//获取连接
        Connection connection = DriverManager.getConnection("jdbc:hive2://cc3.prime:10000/test", "", "");
//执行语句
        PreparedStatement preparedStatement = connection.prepareStatement("select * from test1");
//处理结果
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            System.out.println(resultSet.getString(1));
        }
//关闭资源
        resultSet.close();
        preparedStatement.close();
        connection.close();
    }
}
